<div class="section">

	<div class="section-title">
    	Financial Report
    </div>
    
    <div class="section-content padding1">
    
    	<form id="ProductForm" name="ProductForm"  action="" method="post" enctype="multipart/form-data">
    
    	<div class="left">
            
            <h3>Financial Report</h3>
        
        </div>
        
    	<div class="right">
            
            <a class="button" href="index.php"><?php echo $this->document->text['button_cancel']?></a>
            
        </div>
        <div class="clearer">&nbsp;</div>
        
        
        <div id="container"> 
            <div>                        
                <p>
                    <label>Start date</label>
<script language="javascript">
 	$(function() {
		$("#startdate").datepicker({
				changeMonth: true,
				changeYear: true,
				dateFormat: 'dd-mm-yy'
				});
		});
 </script>
                    <input class="text" type="text" id="startdate" name="startdate" value="<?php echo $startdate?>" />
                    <label>End date</label>
<script language="javascript">
 	$(function() {
		$("#enddate").datepicker({
				changeMonth: true,
				changeYear: true,
				dateFormat: 'dd-mm-yy'
				});
		});
 </script>
                    <input class="text" type="text" id="enddate" name="enddate" value="<?php echo $enddate?>" />
                    <a class="button" onClick="statistics()">Statistics</a>
                </p> 
               
                
            </div>
			<div>                        
                <p>
                    <label>Year</label>
                    <select id="year" name="year">
<?php
	foreach($Year as $item)
    {
    	$sel = "";
    	if($curentyear == $item)
        	$sel='selected="selected"';
?>
						<option value="<?php echo $item?>" <?php echo $sel?> ><?php echo $item?></option>
<?php
    }
?>
                    </select>
                    <label>Month</label>
                    <select id="month" name="month">
<?php
	foreach($Month as $item)
    {
    	$sel = "";
    	if($curentmonth == $item)
        	$sel='selected="selected"';
?>
						<option value="<?php echo $item?>" <?php echo $sel?> ><?php echo $item?></option>
<?php
    }
?>
                    </select>
                    <a class="button" onclick="statisticsByMonth()">Statistics</a>
                </p> 
            </div>
        </div>
        </form>
    </div>
</div>


<div id="reportresult" style="display:none">
            
    <ul>
        <li><a href="#fragment-1"><span>Summary</span></a></li>
        <li><a href="#fragment-2"><span>Sale</span></a></li>
        <li><a href="#fragment-3"><span>Export Product</span></a></li>
        <li><a href="#fragment-4"><span>Import Product</span></a></li>
    </ul>
 
    <div id="fragment-1">
        
        <div class="section" id="final" style="display:none">
            <div class="section-content padding2">
                <div class="text-right large">
                	<h5>Begin Period Balance: <span id="startbalance"></span></h5>
                </div>
                
                <div class="hline">&nbsp;</div><br />

                <div class="text-left">
                	<table class="data-table" width="50%">
                    	<tr>
                        	<td width="50%"><label>Sale: </label></td>
                            <td class="text-right"><span id="saletotalfinal">0</span></td>
                        </tr>
                        <tr>
                        	<td><label>Export: </label></td>
                            <td class="text-right"><span id="exporttotalfinal">0</span></td>
                        </tr>
                        <tr>
                        	<th><label><?php echo $this->document->text['text_income']?>: </label></th>
                            <th class="text-right"><span id="income"></span></th>
                        </tr>
                    </table>
                    
                    <table class="data-table" width="50%">
                        <tr>
                        	<td width="50%"><label>Import: </label></td>
                            <td class="text-right"><span id="importtotalfinal">0</span></td>
                        </tr>
                    </table>
                    
                    <table class="data-table" width="50%">
                        <tr>
                        	<th width="50%"><label>In Period Balance: </label></th>
                            <th class="text-right"><span id="balance"></span></th>
                        </tr>
                    </table>
                    
                </div>
                <div class="hline">&nbsp;</div>
                
                <div class="text-right large">
                	<h5>End Period Balance: <span id="endbalance"></span><br /></h5>
                </div>
                
            </div>
        </div>
        
    </div>
    
    <div id="fragment-2">
        <div class="section" id="sale">
        </div>
    </div>
    
    <div id="fragment-3">
        <div class="section" id="export">
        </div>
    </div>
    
    <div id="fragment-4">
    
        <div class="section" id="import">
        </div>
    
    </div>
        
    
</div>











<script src="<?php echo DIR_JS?>jquery.tabs.pack.js" type="text/javascript"></script>
<script language="javascript">
$(document).ready(function() { 
	$('#reportresult').tabs({ fxSlide: true, fxFade: true, fxSpeed: 'slow' });
});

function statistics()
{
	startdate = $("#startdate").val();
	enddate = $("#enddate").val();
	loadStatistics(startdate,enddate);
	$("#reportresult").show('slow');
}

function statisticsByMonth()
{
	startdate = "01-"+toMonth($("#month").val())+"-"+$("#year").val();
	enddate = daysInMonth($("#month").val(),$("#year").val()) + "-"+ toMonth($("#month").val())+"-"+$("#year").val();
	loadStatistics(startdate,enddate);
	$("#reportresult").show('slow');
}

function loadStatistics(startdate,enddate)
{
	$.blockUI({ message: "<h1>Please wait...</h1>" }); 
	$("#startbalance").load("?route=soft/statistics/getBalance&enddate="+startdate,
	function()
	{
		$("#sale").load("?route=soft/statistics/getList&type=sale&template=soft/sale&startdate="+startdate+"&enddate="+enddate,
						function()
						{
							$("#export").load("?route=soft/statistics/getList&type=export&template=soft/export&startdate="+startdate+"&enddate="+enddate,
											function()
											{
												$("#import").load("?route=soft/statistics/getList&type=import&template=soft/import&startdate="+startdate+"&enddate="+enddate,
																  function()
																  {
																		$("#saletotalfinal").html($("#saletotal").html());
																		$("#exporttotalfinal").html($("#exporttotal").html());
																		$("#importtotalfinal").html($("#importtotal").html());
																		imcome = eval($("#saletotal").html().replace(/,/g,"")) + eval($("#exporttotal").html().replace(/,/g,""));
																		$("#income").html(numberView(imcome));
																		balance = imcome - eval($("#importtotal").html().replace(/,/g,""));
																		$("#balance").html(numberView(balance));
																		balanceend = eval($("#startbalance").html().replace(/,/g,"")) + balance;
																		//alert(balanceend);
																		$("#endbalance").html(numberView(balanceend));
																		$("#final").show();
																		$.unblockUI();
																	});
											});
						});
		
		
	});
}
</script>